<?php
class AdminAction extends Action {
	public function index(){
		$isLogin = session('isLogin');

		if(!$isLogin){
			$this->error('请先登录','index.php?s=Admin/login');
			return 0;
		}

		$admin_name = session('admin_name');
		$permission = session('permission');
		$this->assign('admin_name',$admin_name);
		$this->assign('permission',$permission);
		$this->display();
	} 
	

    public function login(){
	 $this->display();
    }
    public function vote(){
     $this->display();
    }
     public function add(){
	 $this->display();
    }
    public function check(){
    	$name = $_POST['name'];
    	$password = $_POST['password'];
    	if(empty($name)){
    		$this->error("请输入登录名");
    	}
    	if(empty($password)){
    		$this->error("请输入密码");
    	}

    	$User = M("User");
    	$list = $User->where("name='{$name}'")->select();
    	var_dump($list[0]);

    	if($list[0]['password'] == $password){
    		session('isLogin',true);
    		session('admin_name',$list[0]['name']);
    		session('permission',$list[0]['permission']);

    		$this->success('登录成功','admin.php?s=Admin/index');

    	}else{
    		$this -> error('密码错误，请重新输入','admin.php?s=Admin/login');
    	}

    }
}